package com.zxc.controller.service;


import com.zxc.entity.SctService;
import com.zxc.service.SctServiceService;
import com.zxc.utils.IDUtil;
import com.zxc.utils.StringToDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/handleservice")
public class HandlerServiceController {

    @Autowired
    private SctServiceService sctServiceService;

    @RequestMapping("/{skipCount}/{pageSize}")
    @ResponseBody
    public Map<String,Object> getSctServiceListOrByCustName(@PathVariable Integer skipCount,
                                                            @PathVariable Integer pageSize){
        Map<String,Object> modelMap = new HashMap<>();
        int skipCounts = (skipCount-1)*pageSize;
        //根据服务状态，查询出已经分配的服务
        String svrType = "已分配";
        List<SctService> sctServiceList  = sctServiceService.getSctServiceListBySvrStatus(skipCounts,pageSize,svrType);
        modelMap.put("dataList",sctServiceList);
        int total = sctServiceService.selectSctServiceCountByStatus(svrType);
        modelMap.put("total",total);
        return modelMap;
    }

    @RequestMapping(value = "/initSctService/{svrId}")
    @ResponseBody
    public Map<String,Object> sctServiceInit(@PathVariable Integer svrId){
        Map<String,Object> modelMap = new HashMap<>();
        modelMap.put("sctService",sctServiceService.getSctServiceById(svrId));
        return modelMap;
    }

    @RequestMapping(value = "/updateSctService")
    @ResponseBody
    public Map<String,Object> updateSctServiceBysvrId(SctService sctService, String svrDealDateStr){
        Map<String,Object> modelMap = new HashMap<>();
        //需要将处理人的id，日期赋值,状态改为已处理
        sctService.setSvrStatus("已处理");
        sctService.setSvrDealDate(StringToDate.stringToDate(svrDealDateStr));
        if (!sctService.getSvrDealBy().equals("") && sctService.getSvrDealBy() != null){
            sctService.setSvrDealId(IDUtil.createId());
        }
        int result = sctServiceService.updateDistributionById(sctService);
        if (result >=0 ){
            modelMap.put("success",true);
        }else {
            modelMap.put("success",false);
        }
        return modelMap;
    }



}
